package zhihuilan.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import zhihuilan.dto.MySearchDto;
import zhihuilan.entity.MyCategoryShop;
import zhihuilan.entity.MyFactoryProduct;

import java.util.List;

@Mapper
public interface MyFactoryProductMapper extends BaseMapper<MyFactoryProduct> {

    @Select({" <script> select *" +
            " <if test='field != null and field != \"\"'> " +
            "    ${field} \n" +
            " </if> " +
            " from my_factory_product a LEFT JOIN my_shop s on a.shopid = s.id \n"+
            " <where> "+
            "  a.`status` =1 and a.shopid &gt;= 0  and a.factoryid = 0 and (a.price &gt; 0 or a.price_q &gt; 0 or a.price_z &gt; 0 )\n"+
            " <if test='where != null and where != \"\"'> " +
            "   ${where} \n" +
            " </if> " +
            "</where>"+
            " order by " +
            " <if test='order != null and order != \"\"'> " +
            "   ${order} \n" +
            " </if> " +
            "  a.id desc   LIMIT ${page},${pageSize}  " +
            " </script>"})
    List<MyFactoryProduct> selectSearchProduct(@Param("page") Long page, @Param("pageSize") Long pageSize, @Param("field") String field, @Param("where") String where,@Param("order") String order);


    @Select({" <script>select count(*) from ( select a.id " +
            " from my_factory_product a LEFT JOIN my_shop s on a.shopid = s.id \n"+
            " <where> "+
            "  a.`status` =1 and a.shopid &gt;= 0  and a.factoryid = 0  and  (a.price &gt; 0 or a.price_q &gt; 0 or a.price_z &gt; 0 ) \n"+
            " <if test='where != null and where != \"\"'> " +
            "   ${where} \n" +
            " </if> " +
            "</where>"+
            " ) as total  </script>"})
    Long selectSearchProductCount( @Param("where") String where);


    @Select({" <script> select a.*,c.sort sort" +
            " from my_factory_product a RIGHT JOIN my_category_product c on a.pid1 = c.id \n"+
            " <where> "+
            " <if test='shopid != null and shopid != \"\"'> " +
            "   a.shopid = #{shopid} \n" +
            " </if> " +
            " <if test='where != null and where != \"\"'> " +
            " and ( ${where} ) \n" +
            " </if> " +
            "</where>"+
            " order by  sort,id asc " +
            " LIMIT ${page},${pageSize}  " +
            " </script>"})
    List<MyFactoryProduct> selectProductByShopIdKeywordList(@Param("page") Long page, @Param("pageSize") Long pageSize, @Param("shopid") Integer shopid, @Param("where") String where);


    @Select({" <script>select count(*) from ( select a.id " +
            " from my_factory_product a LEFT JOIN my_category_product c on a.pid1 = c.id \n"+
            " <where> "+
            " <if test='shopid != null and shopid != \"\"'> " +
            "   a.shopid = #{shopid} \n" +
            " </if> " +
            " <if test='where != null and where != \"\"'> " +
            "  and ( ${where} ) \n" +
            " </if> " +
            "</where>"+
            " ) as total  </script>"})
    Long selectProductByShopIdKeywordCount( @Param("shopid") Integer shopid, @Param("where") String where);
}
